package aword.analyze ;

import java.util.HashMap;

public class Lists {
	
	protected HashMap<Integer, ListeDef> listDefs ;
	protected HashMap<Integer, Integer> listToDef ;
	
	public Lists() {
		super() ;
		this.listDefs = new HashMap<Integer, ListeDef>() ;
		this.listToDef = new HashMap<Integer, Integer>() ;
	}
	
	public void addDef(ListeDef ld) {
		this.listDefs.put(ld.getId(), ld) ;
	}
	
	public void addList(int idList, int idDef) {
		this.listToDef.put(idList, idDef) ;
	}
	
	public boolean isBulletList(int listId, int level) {
		if (this.listToDef.containsKey(listId)) {
			int def = this.listToDef.get(listId) ;
			if (this.listDefs.containsKey(def)) {
				ListeDef ld = this.listDefs.get(def) ;
				return ld.isBullet(level) ;
			}// if
		}// if
		return false ;
	}
	
	@Override
	public String toString() {
		StringBuilder s = new StringBuilder() ;
		s.append(String.format("Lists : %d definitions, %d lists\n",
				this.listDefs.keySet().size(),
				this.listToDef.keySet().size())) ;
		for(Integer key : this.listToDef.keySet()) {
			s.append(String.format("- list %d -def-> listeDef %d\n",
					key, this.listToDef.get(key))) ;
		}// for
		for(Integer key : this.listDefs.keySet()) {
			s.append(String.format("- listDef %d:\n", key)) ;
			s.append(this.listDefs.get(key)) ; 
		}// for
		return s.toString();
	}
	
}

class ListeDef {
	
	public static final int MAX_LEVEL_DEEPTH = 4 ;
	
	private int id ;
	
	private boolean[] isBullet ;
	
	public ListeDef() {
		super() ;
		this.isBullet = new boolean[MAX_LEVEL_DEEPTH] ;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public int getId() {
		return this.id;
	}
	
	public boolean isBullet(int level) {
		if ((level >= 0) && (level < MAX_LEVEL_DEEPTH)) {
			return this.isBullet[level] ;
		}// if
		return false ;
	}
	
	public void setIsBullet(int level, boolean isBulletList) {
		if ((level >= 0) && (level < MAX_LEVEL_DEEPTH)) {
			this.isBullet[level] = isBulletList ;
		}// if
	}
	
	@Override
	public String toString() {
		StringBuilder s = new StringBuilder() ;
		for(int level=0; level<MAX_LEVEL_DEEPTH; ++level) {
			s.append(String.format("\tlevel %d - bullet? %s\n", 
					level, this.isBullet(level))) ;
		}// for
		return s.toString();
	}
}